package com.ruoyi.dmsIms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dmsIms.domain.TestGlobalVar;
import com.ruoyi.dmsIms.service.ITestGlobalVarService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 变量字典Controller
 * 
 * @author ZhangSiRui
 * @date 2022-01-05
 */
@RestController
@RequestMapping("/dmsIms/globalvar")
public class TestGlobalVarController extends BaseController
{
    @Autowired
    private ITestGlobalVarService testGlobalVarService;

    /**
     * 查询变量字典列表
     */
    @PreAuthorize("@ss.hasPermi('dmsIms:globalvar:list')")
    @GetMapping("/list")
    public TableDataInfo list(TestGlobalVar testGlobalVar)
    {
        startPage();
        List<TestGlobalVar> list = testGlobalVarService.selectTestGlobalVarList(testGlobalVar);
        return getDataTable(list);
    }

    /**
     * 查询变量字典列表
     */
    @GetMapping("/interList/{id}")
    public TableDataInfo interList(@PathVariable("id") String id)
    {
        List<TestGlobalVar> list = testGlobalVarService.selectTestGlobalVarByInterId(id);
        return getDataTable(list);
    }

    /**
     * 导出变量字典列表
     */
    @PreAuthorize("@ss.hasPermi('dmsIms:globalvar:export')")
    @Log(title = "变量字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestGlobalVar testGlobalVar)
    {
        List<TestGlobalVar> list = testGlobalVarService.selectTestGlobalVarList(testGlobalVar);
        ExcelUtil<TestGlobalVar> util = new ExcelUtil<TestGlobalVar>(TestGlobalVar.class);
        util.exportExcel(response, list, "变量字典数据");
    }

    /**
     * 获取变量字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('dmsIms:globalvar:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(testGlobalVarService.selectTestGlobalVarById(id));
    }

    /**
     * 获取变量字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('dmsIms:globalvar:query')")
    @GetMapping(value = "/getInfobyName/{name}")
    public AjaxResult getInfobyName(@PathVariable("name") String name)
    {
        return AjaxResult.success(testGlobalVarService.selectTestGlobalVarByName(name));
    }

    /**
     * 新增变量字典
     */
    @PreAuthorize("@ss.hasPermi('dmsIms:globalvar:add')")
    @Log(title = "变量字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestGlobalVar testGlobalVar)
    {
        TestGlobalVar res = testGlobalVarService.selectTestGlobalVarByName(testGlobalVar.getVarName());
        if (res == null){
            return toAjax(testGlobalVarService.insertTestGlobalVar(testGlobalVar));
        }else{
            return AjaxResult.error("变量名已存在");
        }
    }

    /**
     * 修改变量字典
     */
    @PreAuthorize("@ss.hasPermi('dmsIms:globalvar:edit')")
    @Log(title = "变量字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestGlobalVar testGlobalVar)
    {
        return toAjax(testGlobalVarService.updateTestGlobalVar(testGlobalVar));
    }

    /**
     * 删除变量字典
     */
    @PreAuthorize("@ss.hasPermi('dmsIms:globalvar:remove')")
    @Log(title = "变量字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(testGlobalVarService.deleteTestGlobalVarByIds(ids));
    }
}
